<?php 
namespace Home\Controller;

use Think\Controller;

class UploadController extends Controller
{
	public function index()
	{
		
		
		// $width = $image->width(); // 返回图片的宽度
		// $height = $image->height(); // 返回图片的高度
		// $type = $image->type(); // 返回图片的类型
		// $mime = $image->mime(); // 返回图片的mime类型
		// $size = $image->size(); // 返回图片的尺寸数组 0 图片宽度 1 图片高度
		
		// var_dump($height);die;
		$this->display();
	}

	public function upload()
	{
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize = 3145728 ;// 设置附件上传大小
		$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->rootPath = './Uploads/'; // 设置附件上传根目录
		$upload->savePath = ''; // 设置附件上传（子）目录
		$upload->autoSub = true;//开启子目录保存
		$upload->subName = array('date','Ymd');//以日期为子目录
		// 上传文件
		$info = $upload->upload();
		$iname = $data['img'] = $info['photo']['savename'];
		$data['create_time'] = NOW_TIME;
		$path = $data['path'] = $info['photo']['savepath'];
		// var_dump($iname);
		// var_dump($path);
		// var_dump('./uploads/'.$path.$iname);
		// var_dump($data);die;
		if(!$info) {// 上传错误提示错误信息
			$this->error($upload->getError());
		}else{// 上传成功
			$image = new \Think\Image();
			$image->open('./uploads/'.$path.$iname);
			$image->thumb(80, 80)->save('./uploads/thumb/80_'.$iname);
			// var_dump('./uploads/thumb/50*50_'.$iname);die;
			$this->success('上传成功！');
		}
	}

}